require("GameObjects.WorldObjects.Road")
require("GameObjects.WorldObjects.Grass")
require("GameObjects.WorldObjects.Forrest")
require("GameObjects.WorldObjects.Water")
require("GameObjects.WorldObjects.Big_Rocks")
require("GameObjects.Buildings.Castle")
require("GameObjects.Buildings.Headquarters")
require("GameObjects.Buildings.BarracksCavalry")
require("GameObjects.Buildings.BarracksMelee")
require("GameObjects.Buildings.BarracksRange")
require("GameObjects.Buildings.CapturePointBuilding")
require("GameSetup.Tile")

Map = {}
Map.__index = Map
 
function Map.new()
    local instance = {
    }
    
    setmetatable(instance, Map)
    return instance
end

function Map:getLevelById(levelId)
  if levelId == 1 then return self:getLevel1()
  elseif levelId == 2 then return self:getLevel2()
  elseif levelId == 3 then return self:getLevel3()
  elseif levelId == 4 then return self:getLevel4()
  elseif levelId == 5 then return self:getLevel5()
  elseif levelId == 6 then return self:getLevel6()
  end      
end

function Map:initObjects(_x, _y, _tilesLevelWorld, _tilesLevelBuilding, _tilesLevelUnit)
  local result = {}
  local levelList = { }
  
  for i=1, (xMap*yMap), 1 do
    local tile = Tile.new()
    local world = _tilesLevelWorld[i]
    local building = _tilesLevelBuilding[i]
    local unit = _tilesLevelUnit[i]
    
    self:checkEnvironment(world, tile)
    self:checkBuilding(building, tile)
    self:checkUnit(unit, tile)
    
    levelList[i] = tile
  end
  result[1] = xMap
  result[2] = yMap
  result[3] = levelList
  
  camMapX = 0
  camMapY = 0
  
  return result
end

function Map:getLevel1()

  local tilesLevelWorld =     { "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Forrest1","Forrest1", "Forrest1",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Forrest1","Forrest1","Forrest1", "Forrest1",
                                "Forrest1","Forrest1","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Forrest1", "Forrest1",
                                "Forrest1","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass" }
                              
  local tilesLevelBuilding =  { "Headquarters-player1","", "BarracksMelee-player1", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "BarracksMelee-player2", "", "Headquarters-player2" }
                              
  local tilesLevelUnit =      { "","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","Archer", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "" }

  xMap = 12
  yMap = 10
  
  return self:initObjects(xMap, yMap, tilesLevelWorld, tilesLevelBuilding, tilesLevelUnit)
end

function Map:getLevel2()

  local tilesLevelWorld =     { "Forrest1",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Forrest1","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Big_Rocks","Big_Rocks", "Big_Rocks",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Horizontal","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Big_Rocks","Big_Rocks", "Big_Rocks",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Forrest1","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Forrest1" }
                              
  local tilesLevelBuilding =  { "","", "", "", "",
                                "BarracksMelee-player1","BarracksCavalry-player1", "", "", "","","", "", "", "",
                                "","", "Headquarters-player1", "", "","","", "", "", "",
                                "","", "", "Castle-player1", "","Castle-player1","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "Castle-neutral",
                                "","", "", "", "","","", "", "", "Castle-neutral",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "Castle-player2", "","Castle-player2","", "", "", "",
                                "","", "", "", "","","Headquarters-player2", "", "", "",
                                "","", "", "", "","","", "", "BarracksMelee-player2", "BarracksCavalry-player2",
                                "","", "", "", "" }
                              
  local tilesLevelUnit =      { "","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "" }

  xMap = 12
  yMap = 10
  
  return self:initObjects(xMap, yMap, tilesLevelWorld, tilesLevelBuilding, tilesLevelUnit)
end

function Map:getLevel3()

  local tilesLevelWorld =     { "Grass",
                                "Grass","Grass","Forrest1","Grass", "Road_Vertical",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Forrest1",
                                "Grass","Road_Vertical","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Forrest1", "Grass",
                                "Grass","Forrest1","Grass","Road_Vertical", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Road_Vertical","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Road_Vertical","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Road_Horizontal",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Split1",
                                "Road_Split2","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Horizontal","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Road_Vertical","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass", "Road_Vertical",
                                "Grass","Forrest1","Grass","Grass", "Forrest1",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Road_Vertical","Grass","Forrest1", "Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Road_Vertical", "Grass",
                                "Forrest1","Grass","Grass","Grass" }
                              
  local tilesLevelBuilding =  { "BarracksMelee-player1","Headquarters-player1", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "Castle-player1","Castle-player1", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "Castle-player2", "Castle-player2",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "Headquarters-player2", "BarracksMelee-player2" }
                              
  local tilesLevelUnit =      { "","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "" }

  xMap = 12
  yMap = 10
  
  return self:initObjects(xMap, yMap, tilesLevelWorld, tilesLevelBuilding, tilesLevelUnit)
end

function Map:getLevel4()

  local tilesLevelWorld =     { "Grass",
                                "Big_Rocks","Big_Rocks","Big_Rocks","Grass","Forrest1",
                                "Forrest1","Forrest1","Grass","Road_Vertical", "Grass",
                                "Grass","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal", "Road_Horizontal",
                                "Road_Loop1","Grass","Grass","Grass","Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass","Grass",
                                "Grass","Grass","Road_Split2","Grass", "Grass",
                                "Grass","Grass","Forrest2","Forrest1","Grass",
                                "Forrest2","Forrest1","Grass","Grass", "Road_Vertical",
                                "Grass","Grass","Grass","Grass","Grass",
                                "Forrest1","Forrest1","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass","Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Loop1","Grass",
                                "Grass","Grass","Grass","Grass", "Road_Loop4",
                                "Road_Loop1","Grass","Grass","Grass","Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Road_Vertical","Grass","Grass","Grass",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Road_Loop2","Road_Split1","Road_Loop1",
                                "Grass","Grass","Grass","Grass", "Grass",
                                "Grass","Grass","Grass","Grass","Grass",
                                "Grass","Grass","Grass","Grass" }
                              
  local tilesLevelBuilding =  { "","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "BarracksCavalry-player1",
                                "","", "", "", "","","", "", "", "",
                                "","", "BarracksRange-player1", "", "BarracksMelee-player1","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","Headquarters-player1","", "Castle-player1", "", "",
                                "","", "", "", "Castle-player2","","Headquarters-player2", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","BarracksMelee-player2", "", "BarracksRange-player2", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "BarracksCavalry-player2", "", "","","", "", "", "",
                                "","", "", "", "" }
                              
  local tilesLevelUnit =      { "","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "","","", "", "", "",
                                "","", "", "", "" }

  xMap = 12
  yMap = 10
  
  return self:initObjects(xMap, yMap, tilesLevelWorld, tilesLevelBuilding, tilesLevelUnit)
end

function Map:getLevel5()

  local tilesLevelWorld = { 
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Grass","Grass","Forrest1","Forrest1","Road_Vertical","Grass","Grass",
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Grass","Road_Loop1","Forrest1","Forrest1","Road_Vertical","Grass","Grass",
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Forrest1","Forrest1","Forrest1","Forrest1","Road_Vertical","Grass","Grass",
    "Grass","Grass","Road_Split4","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Split3","Grass","Grass",
    "Grass","Grass","Road_Vertical","Grass","Grass","Grass","Grass","Grass","Grass","Road_Vertical","Grass","Grass", 
    "Grass","Grass","Road_Vertical","Grass","Grass","Grass","Grass","Grass","Grass","Road_Vertical","Grass","Grass",
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Grass","Grass","Grass","Forrest1","Road_Vertical","Grass","Forrest1",
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Grass","Grass","Grass","Forrest1","Road_Vertical","Forrest1","Grass",
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Forrest1","Forrest1","Grass","Grass","Road_Vertical","Grass","Grass",
    "Grass","Grass","Road_Vertical","Forrest1","Forrest1","Forrest1","Forrest1","Forrest1","Forrest1","Road_Vertical","Grass","Grass" }
                              
  local tilesLevelBuilding =  { 
    "","","","","","","BarracksCavalry-neutral","","","","","",
    "","","","","","CapturePointBuilding-neutral","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","Castle-neutral","","","","","","","Castle-neutral","","",
    "","","","","","","","","","","","",
    "","","","","","BarracksRange-neutral","","","","","","",
    "","","","","","","","","","","","",
    "","BarracksMelee-player1","","","","","","","","","BarracksMelee-player2","",
    "Headquarters-player1","","","","","","","","","","","Headquarters-player2"}
                              
  local tilesLevelUnit =      { 
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","",""}

  xMap = 12
  yMap = 10
  
  return self:initObjects(xMap, yMap, tilesLevelWorld, tilesLevelBuilding, tilesLevelUnit)
end

function Map:getLevel6()

  local tilesLevelWorld = { 
    "Grass","Grass","Grass","Grass","Water2","Water1","Water1","Water3","Grass","Grass","Grass","Grass",
    "Grass","Grass","Grass","Grass","Water2","Water1","Water1","Water3","Grass","Grass","Grass","Grass",
    "Grass","Grass","Grass","Grass","Water7","Water5","Water5","Water8","Grass","Grass","Grass","Grass",
    "Forrest1","Forrest1","Grass","Grass","Forrest2","Forrest2","Forrest2","Forrest2","Grass","Grass","Forrest1","Forrest1",
    "Road_Split2","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Loop3","Grass","Grass","Grass","Grass","Forrest1","Road_Vertical", 
    "Road_Vertical","Forrest1","Grass","Grass","Grass","Road_Loop2","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Horizontal","Road_Split1",
    "Water11","Water12","Grass","Grass","Forrest2","Forrest2","Forrest2","Forrest2","Grass","Grass","Water13","Water11",
    "Grass","Grass","Grass","Grass","Water6","Water4","Water4","Water9","Grass","Grass","Grass","Grass",
    "Grass","Grass","Grass","Grass","Water2","Water1","Water1","Water3","Grass","Grass","Grass","Grass",
    "Grass","Grass","Grass","Grass","Water2","Water1","Water1","Water3","Grass","Grass","Grass","Grass" }
                              
  local tilesLevelBuilding =  { 
    "","","","","","","","","","","","",
    "","BarracksRange-player1","","","","","","","","","BarracksMelee-player2","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "BarracksCavalry-player1","","","","Castle-neutral","","CapturePointBuilding-neutral","","","","","Headquarters-player2",
    "Headquarters-player1","","","","","","","Castle-neutral","","","","BarracksCavalry-player2",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","BarracksMelee-player1","","","","","","","","","BarracksRange-player2","",
    "","","","","","","","","","","",""}
                              
  local tilesLevelUnit =      { 
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","","",
    "","","","","","","","","","","",""}

  xMap = 12
  yMap = 10
  
  return self:initObjects(xMap, yMap, tilesLevelWorld, tilesLevelBuilding, tilesLevelUnit)
end

function Map:checkEnvironment(world, tile)
  if world == "Grass" then
    local Grass = Grass.new()
    tile:setWorldObject(Grass)  
  elseif world == "Mountain" then
    local mountain = Mountain.new()
    tile:setWorldObject(mountain)
  elseif world == "Big_Rocks" then
    local rocks = Big_Rocks.new()
    tile:setWorldObject(rocks)
  elseif world == "Bridge" then
      
  elseif world == "Forrest1" then
    local forrest = Forrest.new()
    forrest:setType("Forrest1")
    tile:setWorldObject(forrest) 
  elseif world == "Forrest2" then
    local forrest = Forrest.new()
    forrest:setType("Forrest2")
    tile:setWorldObject(forrest) 
  elseif world == "Road_Horizontal" then
    local road = Road.new()
    road:setType("Road_Horizontal")
    tile:setWorldObject(road)
  elseif  world == "Road_Loop1" then
    local road = Road.new()
    road:setType("Road_Loop1")
    tile:setWorldObject(road)
  elseif  world == "Road_Loop2" then
    local road = Road.new()
    road:setType("Road_Loop2")
    tile:setWorldObject(road)
  elseif  world == "Road_Loop3" then
    local road = Road.new()
    road:setType("Road_Loop3")
    tile:setWorldObject(road)
  elseif  world == "Road_Loop4" then
    local road = Road.new()
    road:setType("Road_Loop4")
    tile:setWorldObject(road)
  elseif  world == "Road_Split1" then
    local road = Road.new()
    road:setType("Road_Split1")
    tile:setWorldObject(road)
  elseif  world == "Road_Split2" then
    local road = Road.new()
    road:setType("Road_Split2")
    tile:setWorldObject(road)
  elseif  world == "Road_Split3" then
    local road = Road.new()
    road:setType("Road_Split3")
    tile:setWorldObject(road)
  elseif  world == "Road_Split4" then
    local road = Road.new()
    road:setType("Road_Split4")
    tile:setWorldObject(road)
  elseif world == "Road_Vertical" then
    local road = Road.new()
    road:setType("Road_Vertical")
    tile:setWorldObject(road)
  elseif world == "Small_Rocks" then
    
  elseif world == "Water1" then
    local water = Water.new()
    water:setType("Water1")
    tile:setWorldObject(water)
  elseif world == "Water2" then
    local water = Water.new()
    water:setType("Water2")
    tile:setWorldObject(water)
  elseif world == "Water3" then
    local water = Water.new()
    water:setType("Water3")
    tile:setWorldObject(water)
  elseif world == "Water4" then
    local water = Water.new()
    water:setType("Water4")
    tile:setWorldObject(water)
  elseif world == "Water5" then
    local water = Water.new()
    water:setType("Water5")
    tile:setWorldObject(water)
  elseif world == "Water6" then
    local water = Water.new()
    water:setType("Water6")
    tile:setWorldObject(water)
  elseif world == "Water7" then
    local water = Water.new()
    water:setType("Water7")
    tile:setWorldObject(water)
  elseif world == "Water8" then
    local water = Water.new()
    water:setType("Water8")
    tile:setWorldObject(water)
  elseif world == "Water9" then
    local water = Water.new()
    water:setType("Water9")
    tile:setWorldObject(water)
  elseif world == "Water10" then
    local water = Water.new()
    water:setType("Water10")
    tile:setWorldObject(water)
  elseif world == "Water11" then
    local water = Water.new()
    water:setType("Water11")
    tile:setWorldObject(water)
  elseif world == "Water12" then
    local water = Water.new()
    water:setType("Water12")
    tile:setWorldObject(water)
  elseif world == "Water13" then
    local water = Water.new()
    water:setType("Water13")
    tile:setWorldObject(water)
  end
end

function Map:checkBuilding(building, tile)
  if building == "Castle-player1" then 
      local castle = Castle.new()
      castle:setType("Castle-player1")
      castle:setOwner("playerOne")
      castle:setOwnerObject(pl1)
      castle:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(castle)
      pl1:addBuildingToList(castle)   
      
    elseif building == "Castle-player2" then
      local castle = Castle.new()
      castle:setType("Castle-player2")
      castle:setOwner("playerTwo")
      castle:setOwnerObject(pl2)
      castle:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(castle)
      pl2:addBuildingToList(castle)
      
    elseif building == "Castle-neutral" then
      local castle = Castle.new()
      castle:setType("Castle-neutral")
      castle:setOwner("neutral")
      castle:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(castle)
      
    elseif building == "BarracksCavalry-player1" then
      local barracks = BarracksCavalry.new()
      barracks:setType("BarracksCavalry-player1")
      barracks:setOwner("playerOne")
      barracks:setOwnerObject(pl1)
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      pl1:addBuildingToList(barracks) 
      
    elseif building == "BarracksCavalry-player2" then
      local barracks = BarracksCavalry.new()
      barracks:setType("BarracksCavalry-player2")
      barracks:setOwner("playerTwo")
      barracks:setOwnerObject(pl2)
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      pl2:addBuildingToList(barracks)
      
    elseif building == "BarracksCavalry-neutral" then
      local barracks = BarracksCavalry.new()
      barracks:setType("BarracksCavalry-neutral")
      barracks:setOwner("neutral")
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      
    elseif building == "BarracksMelee-player1" then
      local barracks = BarracksMelee.new()
      barracks:setType("BarracksMelee-player1")
      barracks:setOwner("playerOne")
      barracks:setOwnerObject(pl1)
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      pl1:addBuildingToList(barracks)
      
    elseif building == "BarracksMelee-player2" then
      local barracks = BarracksMelee.new()
      barracks:setType("BarracksMelee-player2")
      barracks:setOwner("playerTwo")
      barracks:setOwnerObject(pl2)
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      pl2:addBuildingToList(barracks) 
      
    elseif building == "BarracksMelee-neutral" then
      local barracks = BarracksMelee.new()
      barracks:setType("BarracksMelee-neutral")
      barracks:setOwner("neutral")
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      
    elseif building == "BarracksRange-player1" then
      local barracks = BarracksRange.new()
      barracks:setType("BarracksRange-player1")
      barracks:setOwner("playerOne")
      barracks:setOwnerObject(pl1)
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      pl1:addBuildingToList(barracks) 
      
    elseif building == "BarracksRange-player2" then
      local barracks = BarracksRange.new()
      barracks:setType("BarracksRange-player2")
      barracks:setOwner("playerTwo")
      barracks:setOwnerObject(pl2)
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      pl2:addBuildingToList(barracks)
      
    elseif building == "BarracksRange-neutral" then
      local barracks = BarracksRange.new()
      barracks:setType("BarracksRange-neutral")
      barracks:setOwner("neutral")
      barracks:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(barracks)
      
    elseif building == "Farm" then
          
    elseif building == "Headquarters-player1" then
      local headquarters = Headquarters.new()
      headquarters:setType("Headquarters-player1")
      headquarters:setOwner("playerOne")
      headquarters:setOwnerObject(pl1)
      headquarters:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(headquarters)
      pl1:addBuildingToList(headquarters)
      
    elseif building == "Headquarters-player2" then
      local headquarters = Headquarters.new()
      headquarters:setType("Headquarters-player2")
      headquarters:setOwner("playerTwo")
      headquarters:setOwnerObject(pl2)
      headquarters:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(headquarters)
      pl2:addBuildingToList(headquarters)
      
    elseif building == "CapturePointBuilding-neutral" then
      local capturePoint = CapturePointBuilding.new()
      capturePoint:setType("CapturePointBuilding-neutral")
      capturePoint:setOwner("neutral")
      capturePoint:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(capturePoint)
      
    elseif building == "CapturePointBuilding-player1" then
      local capturePoint = CapturePointBuilding.new()
      capturePoint:setType("CapturePointBuilding-player1")
      capturePoint:setOwner("playerOne")
      capturePoint:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(capturePoint)
      pl1:addBuildingToList(capturePoint)
      
    elseif building == "CapturePointBuilding-player2" then
      local capturePoint = CapturePointBuilding.new()
      capturePoint:setType("CapturePointBuilding-player2")
      capturePoint:setOwner("playerTwo")
      capturePoint:setTileWhichPlacedOn(tile)
      
      tile:setBuilding(capturePoint)
      pl2:addBuildingToList(capturePoint)
    end
end

function Map:checkUnit(unit, tile)
   if unit == "Archer" then

    elseif unit == "Crossbow" then
      
    elseif unit == "Heavy_Horse" then
      
    elseif unit == "Light_Horse" then
        
    elseif unit == "Spearmen" then
          
    elseif unit == "SpearThrower" then
      
    elseif unit == "SwordFighter" then
      
    end
end

return Map